package com.key.web_admin.controller;

import com.key.common.base.RespResult;
import com.key.modules.dto.LoginFormDTO;
import com.key.modules.service.SysUserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * @Author：朕
 * @Package：com.key.web_admin.controller
 * @Project：logistics_system
 * @name：LoginController
 * @Date：2023/3/23 20:34
 * @Filename：LoginController
 */
@RestController
public class LoginController {
    @Autowired
    private SysUserService sysUserService;

    @PostMapping("/sulogin")
    public RespResult sulogin(@RequestBody LoginFormDTO loginFormDTO, HttpServletResponse response){
        return sysUserService.login(loginFormDTO,response);
    }

    @GetMapping("/logout")
    public RespResult logout(){
        Subject subject = SecurityUtils.getSubject();//admin kzz zss
        // 将Shiro中用户认证的信息清空--退出
        subject.logout();
        return RespResult.success();
    }
}
